package com.easy.service.Impl;

import com.easy.bean.Donation;
import com.easy.bean.Orders;
import com.easy.mapper.DonationMapper;
import com.easy.service.DonationService;
import com.easy.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true) // 默认只读
public class DonationServiceImpl implements DonationService {
    @Autowired
    DonationMapper donationMapper;
    @Override
    @Transactional(rollbackFor = Exception.class) // 写操作
    public Donation add(Donation donation) {
        Orders orders = new Orders();

        donationMapper.add(donation);
        Donation result = donationMapper.one(donation.getDonation_id());
        return result;
    }

    @Override
    @Transactional(rollbackFor = Exception.class) // 写操作
    public int del(Integer id) {
        return donationMapper.del(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class) // 写操作
    public Donation edit(Donation donation) {
        donationMapper.edit(donation);
        Donation result = donationMapper.one(donation.getDonation_id());
        return result;
    }

    @Override
    @Transactional(rollbackFor = Exception.class) // 写操作
    public List<Donation> all(Donation donation) {
        return donationMapper.all(donation);
    }

    @Override
    @Transactional(rollbackFor = Exception.class) // 写操作
    public Donation one(Integer id) {
        return donationMapper.one(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class) // 写操作
    public void page(Page page, Donation donation) {

        int count=donationMapper.pageCount(donation);
        Object data=donationMapper.page(page,donation);
        page.setCount(count);
        page.setData(data);
    }
}
